package com.tyut.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.tyut.entity.Address;
import com.tyut.mapper.AddressMapper;
import com.tyut.service.AddressService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 李嘉昕
 * @since 2025-04-01
 */
@Service
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {
    @Override
    public String setAddress(Address address) {
        QueryWrapper<Address> wrapper = new QueryWrapper<>();
        wrapper.eq("user_id", address.getUserId());
        // 如果存在，则更新
        if (this.getOne(wrapper) != null) {
            this.updateById(address);
        }else {
            this.save(address);
        }
        return address.getPosition() + address.getDetail();
    }
}
